const http = function ({ url, method = 'GET', data = {} } = option) {
  return new Promise((resolve, reject) => {
    if (!url) return reject('url 不能为空');
    // console.log(res)
    wx.request({
      url: url, //仅为示例，并非真实的接口地址        
      data: data,
      method: method,
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8', // 默认值
        token: '50a00a9b8d3402ed4f1b3ed4b890294b',
        uid: wx.getStorageSync('uid')
      },
      success(res) {
        console.log('接口: ' + url);
        // console.log(res)
        // console.log(res.data);
        if (res.statusCode === 500) {
          console.log(res.statusCode);
          wx.redirectTo({
            url: '/pages/index/index'
          })
        };
        if (res.statusCode === 200) {
          resolve(res.data);
          // console.log(res)
          if (res.data.error_code === 501) {
            wx.redirectTo({
              url: '/pages/logIn/logIn'
              // url: '/pages/personal/personal'
            })
          }
        }
      },
      fail(err) {
        reject(err);
      }
    })
  })
}

module.exports = http;